﻿using MetroNextTools.NHelper;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace MetroNextTools.NPanel
{
    public class NOrientationVirtualizingPanel : NVirtualizingPanel
    {
        #region Fields
        private ScrollViewer _snapScrollViewer = null;
        #endregion

        #region Constructor

        public NOrientationVirtualizingPanel()
        {
            this.Loaded += NOrientationVirtualizingPanelLoaded;//TODO Event Memory Leak
        }

        #endregion

        #region EventHandler

        void NOrientationVirtualizingPanelLoaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= NOrientationVirtualizingPanelLoaded;

            _snapScrollViewer = this.Ancestors().OfType<ScrollViewer>().FirstOrDefault();
            //注册滚动事件
            _snapScrollViewer.ViewChanged += OnViewChanged;
        }

        void OnViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
        {
            this.Scrolling();
        }

        #endregion

        #region Depenedency Property

        #region Orientation Property

        public Orientation Orientation
        {
            get { return (Orientation)GetValue(OrientationProperty); }
            set { SetValue(OrientationProperty, value); }
        }

        public static readonly DependencyProperty OrientationProperty =
            DependencyProperty.Register("Orientation", typeof(Orientation), typeof(NOrientationVirtualizingPanel), new PropertyMetadata(Orientation.Horizontal, new PropertyChangedCallback(OnOrientaionChanged)));

        private static void OnOrientaionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {

        }

        #endregion

        

        #endregion

        #region Property
        public ScrollViewer ScrollOwner
        {
            get { return _snapScrollViewer; }
        }
        #endregion
        
        #region Method

        protected virtual void Scrolling()
        {

        }

        #endregion


        public override void Scroll()
        {
            throw new System.NotImplementedException();
        }

        public override Windows.Foundation.Rect CaculatePosition(NData.INRaitoItem ratioItem)
        {
            throw new System.NotImplementedException();
        }

        public override double GetMaxLength()
        {
            throw new System.NotImplementedException();
        }
    }
}
